home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / share / doc / libhtml-parser-perl / examples / hdump < prev    next >
Encoding:
Text File  |  2008-04-04  |  541 b   |  24 lines

  1. #!/usr/bin/perl -w
  2.  
  3. use HTML::Parser ();
  4. use Data::Dump ();
  5.  
  6. sub h {
  7.     my($event, $line, $column, $text, $tagname, $attr) = @_;
  8.  
  9.     my @d = (uc(substr($event,0,1)) . " L$line C$column");
  10.     substr($text, 40) = "..." if length($text) > 40;
  11.     push(@d, $text);
  12.     push(@d, $tagname) if defined $tagname;
  13.     push(@d, $attr) if $attr;
  14.  
  15.     print Data::Dump::dump(@d), "\n";
  16. }
  17.  
  18. my $p = HTML::Parser->new(api_version => 3);
  19. $p->handler(default => \&h, "event, line, column, text, tagname, attr");
  20.  
  21. $p->parse_file(@ARGV ? shift : *STDIN);
  22.  
  23.  
  24.